-----------------------------------------------------------------------------
--  Author(s): GPG + Paulus Cyril
--  Summary  : SC2 UEF Engineer Tower: UXB0101
-- 	Todo	 : Fix assist
--           : Research
--			 : Icon
-----------------------------------------------------------------------------
local StructureUnit = import('/lua/sim/StructureUnit.lua').StructureUnit
local DefaultProjectileWeapon = import('/lua/sim/DefaultWeapons.lua').DefaultProjectileWeapon

UUB0101 = Class(StructureUnit) {
  	
	OnCreate = function(self, createArgs)
		StructureUnit.OnCreate(self, createArgs)
		self:SetBuilderAutoRepair(true)
		self:HideBone('UUB0302_Cord01',true)
		self:HideBone('UUB0302_Cord02',true)
		self:HideBone('UUB0302_Cord03',true)
	end,
	
	 OnStartBuild = function(self, unitBeingBuilt, order )
	    StructureUnit.OnStartBuild(self,unitBeingBuilt, order)
				
        self.UnitBeingBuilt = unitBeingBuilt
        self.UnitBuildOrder = order
        self.BuildingUnit = true
        local bp = self:GetBlueprint()

		if self.UnitBeingBuilt and not self.UnitBeingBuilt:IsDead() and
			self.UnitBeingBuilt.BuildScaffoldUnit and not self.UnitBeingBuilt.BuildScaffoldUnit:IsDead() then
			self.UnitBeingBuilt.BuildScaffoldUnit:OnUnpaused()
		end
      
		self:StartBuildingEffects( unitBeingBuilt, order )
    end,
    

    OnStopBuild = function(self, unitBeingBuilt)
        StructureUnit.OnStopBuild(self,unitBeingBuilt)

		if self.UnitBeingBuilt and not self.UnitBeingBuilt:IsDead() and
			self.UnitBeingBuilt.BuildScaffoldUnit and not self.UnitBeingBuilt.BuildScaffoldUnit:IsDead() then
			self.UnitBeingBuilt.BuildScaffoldUnit:OnPaused()
		end
        self.UnitBeingBuilt = nil
        self.UnitBuildOrder = nil
        self.BuildingUnit = false
    end,    
    
    OnPaused = function(self)
        --When construction is paused take some action
        self:StopUnitAmbientSound( 'ConstructLoop' )
        StructureUnit.OnPaused(self)
        if self.BuildingUnit then
            StructureUnit.StopBuildingEffects(self, self:GetUnitBeingBuilt())
        end
    end,

    OnUnpaused = function(self)
        if self.BuildingUnit then
            self:PlayUnitAmbientSound( 'ConstructLoop' )
            StructureUnit.StartBuildingEffects(self, self:GetUnitBeingBuilt(), self.UnitBuildOrder)
        end
        StructureUnit.OnUnpaused(self)
    end,    

	CreateBuildEffects = function( self, unitBeingBuilt, order )
		CreateRepairBeams( self, unitBeingBuilt, self:GetBlueprint().Build.EffectBones, self.BuildEffectsBag )
    end,
	
}
TypeClass = UUB0101